package com.zksite.nator.client.server.initialzer;

import com.zksite.nator.client.server.handler.ForwardHandle;
import com.zksite.nator.common.context.SpringApplicationContext;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpObjectAggregator;

public class ForwardInitializer extends ChannelInitializer<Channel> {
	private Channel channel;

	private String forwardid;

	public ForwardInitializer(Channel channel, String forwardid) {
		this.channel = channel;
		this.forwardid = forwardid;
	}

	@Override
	protected void initChannel(Channel ch) throws Exception {
		ch.pipeline().addLast(new HttpClientCodec());
		ch.pipeline().addLast("aggregator", new HttpObjectAggregator(Integer.MAX_VALUE));
		ForwardHandle forwardHandle = SpringApplicationContext.getBean(ForwardHandle.class);
		forwardHandle.init(channel, forwardid);
		ch.pipeline().addLast(forwardHandle);

	}
}
